class PwdManage{
    constructor(divId,formId){

        this.divId = divId;

        this.formId = formId;

    }

    start(){
        let load = this;

        $('#'+load.divId).show().siblings().hide();

        load.render();

    }

    render(){
        let load = this;

        load.addEvent();
    }

    addEvent(){
        let load = this;
        $("#"+load.formId).on("submit",function(e){


            e.preventDefault();

            var formData = $(this).serializeArray();

            let accData = {};

            for(let i=0;i<formData.length;i++){
                accData[formData[i]['name']] = formData[i]['value'];
            }

            if(accData['newPwd'] != accData['tmpPwd']){
                layer.msg("密码不一致，请重新输入",{icon: 5,time: 2000});
                return;
            }


            $.post("/Lock/Pwd/Change",{'oldPwd': accData['oldPwd'],'newPwd': accData['newPwd']},function(res){
                if(res.statue == 0){
                    // 添加成功后应该跳转
                    layer.msg(res.message, {icon: 6});  
                    $("#"+load.formId+" button[type=reset]").click();
                    layer.close(load.addLayerindex);

                }else{
                    if(res.statue == 1){
                        $("#"+load.formId+" input[name=oldPwd]").prop('value','');  
                        layui.form.render();
                    }
                    layer.msg(res.message,{icon: 5,time: 2000});
                }
            });

        })
    }
}